/***
 * File		: Vector3.java
 * Subject	: Represents a point in 3D
 * Author	: Isaac Parenteau (locus2k@gmail.com)
 * Date		: April 16th 2011
 */
package src.project.util;

public class Vector3 {
	
	public static Vector3 Up = new Vector3(0f, 1f, 0f);
	public static Vector3 Zero = new Vector3(0, 0, 0);
	public static Vector3 One = new Vector3(1, 1, 1);
	
	public float X;
	public float Y;
	public float Z;
	
	/**
	 * Default constructor
	 */
	public Vector3(){
		this(0, 0, 0);
	}
	
	/**
	 * Constructor that only takes an x and y coordinates
	 * sets the z location to 0
	 * @param x X coordinate
	 * @param y Y coordinate
	 */
	public Vector3(float x, float y){
		this(x, y, 0f);
	}
	
	/**
	 * Constructor that sets all three coordinates
	 * @param x X coordinate
	 * @param y Y coordinate
	 * @param z Z coordinate
	 */
	public Vector3(float x, float y, float z){
		X = x;
		Y = y;
		Z = z;
	}
	
	/**
	 * Gets the distance between the vector and another
	 * @param other the other vector to get the distance from
	 * @return distance
	 */
	public float distance(Vector3 other){
		
		float xDif = X - other.X;
		float yDif = Y - other.Y;
		float zDif = Z - other.Z;
		
		xDif *= xDif;
		yDif *= yDif;
		zDif *= zDif;
		
		float distance = (float) Math.sqrt(xDif + yDif + zDif);
		
		return distance;
	}
	
	/**
	 * Normalizes the vector with another vector
	 * @param other the other vector
	 * @return A normalized vector
	 */
	public Vector3 normalize(Vector3 other){
		
		float distance = distance(other);
		
		float x = X / distance;
		float y = Y / distance;
		float z = Z / distance;
		
		return new Vector3(x, y, z);
	}
	
	/**
	 * Adds another vector to the current vector
	 * @param other the other vector to add
	 * @return
	 */
	public Vector3 add(Vector3 other){
		return new Vector3(this.X + other.X, this.Y + other.Y, this.Z + other.Z);
	}
}
